#include "bsp_beep.h"
#include "bsp_gpio.h"
#include "bsp_delay.h"

void beep_init(void){
	gpio_pin_config_t config;

	/* 复用为GPIO */
	IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01, 0);

	/* 设置电气特性 */
	IOMUXC_SetPinConfig(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01, 0x10B0);

	//GPIO5->GDIR |= (1<<1);		//bit1置位，GPIO为输出模式
	//GPIO5->DR &= ~(1<<1);		//bit1清零，输出低电平时蜂鸣器开启

	config.directioin = kGPIO_DigitalOutput;		//bit1清零，输出低电平时蜂鸣器开启
	config.outputLogic = 1;							//bit1置1， 输出高电平时蜂鸣器关闭
	gpio_init(GPIO5, 1, &config);
}

void beep_switch(int status)
{
	if(status == ON)
		//GPIO5->DR &= ~(1<<1);			//bit1清零，输出低电平时蜂鸣器开启
		gpio_pinwrite(GPIO5, 1, 0);		//bit1置位，输出高电平时蜂鸣器关闭
	else if (status == OFF)
		//GPIO5->DR 1= (1<<1);			//bit1置位，输出高电平时蜂鸣器关闭
		gpio_pinwrite(GPIO5, 1, 1);		//bit1置位，输出高电平时蜂鸣器关闭
}

void beep_times(int n)
{
	int state = 0;
	if(n > 0)
	{
		while(n--){
			state = !state;
			beep_switch(state);
			delay(50);
		}
	}
}